﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Asplode.Events;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Asplode.Renderer
{
    public class AsplodeRendererEventHandler :
            BoxSpawnEventHandler,
            HumanSpawnEventHandler,
            RemoveEntityEventHandler,
            ZombieSpawnEventHandler
    {

        public AsplodeRenderer Renderer { get; set; }

        public AsplodeRendererEventHandler(AsplodeRenderer renderer)
        {
            Renderer = renderer;
        }

        public void handle(BoxSpawnEvent t)
        {
            Model model = Renderer.game.Content.Load<Model>("Models\\cube");
            RenderPair rp = new RenderPair(t.Box, model);
            rp.transform = Matrix.CreateScale(t.Box.width, t.Box.height, t.Box.length);
            Renderer.models.Add(rp);

        }

        public void handle(RemoveEntityEvent t)
        {
            foreach (RenderPair rp in Renderer.models)
            {
                if (rp.Entity == t.entity)
                {
                    Renderer.models.Remove(rp);
                    return;
                }
            }
        }

        public void handle(ZombieSpawnEvent anEvent)
        {
            Model model = Renderer.game.Content.Load<Model>("Models\\Zombie");
            Renderer.models.Add(new RenderPair(anEvent.entity, model));
        }

        public void handle(HumanSpawnEvent t)
        {
            Model model = Renderer.game.Content.Load<Model>("Models\\character");
            Renderer.models.Add(new RenderPair(t.entity, model));
        }
    }
}
